/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.Dictionary;
import java.util.*;
import java.net.*;
import java.io.*;
/**
 *
 * @author BunEri0463
 */
public class Parser {
    private String word="http://definr.com/definr/show/";
    public Parser(String site) //Constructor for parser
    {
      word+=site;
    }
    
    public String retrieve() throws IOException
    {
        URLConnection conn = new URL(word).openConnection();//starts connectionto definr
	InputStreamReader reader=new InputStreamReader(conn.getInputStream(), "US-ASCII");//creates reader 
        BufferedReader r=new BufferedReader(reader);//creates buffered reader using reader
        ArrayList<Integer> a=new ArrayList<Integer>();//web page in in decimal form
        boolean reading=true;
        String def="";
        while (reading)//reads in web page to a
        {
         a.add(new Integer(r.read()));
         if(a.get(a.size()-1)==-1)
           reading =false;
        }
        for (int x=0; x<a.size()-1; x++)
        {       
         def+=(char)a.get(x).intValue();
        }
        return def;
    }
    
    public String parse(String def)//parses out html tags
    {
      def=def.replaceAll("\\<[^\\>]+\\>","");//removes everything in between <> including <>
      def=def.replaceAll("&nbsp;","");//removes &nbsp
      def=def.replaceFirst("\n","");//gets rid of \n at beggining
      return def;
    }
    
    /*
     public static void main (String[] args)
    {
        Parser z=new Parser("gaunt");
        String def="";
        try{
            def=z.retrieve();
            def=z.parse(def);
        }
        catch (Exception e)
        {
         System.out.println("No connection, make sure you are connected to the internet");
        }
        
        System.out.println(def);
        
    }*/
}
